<%@include file="/include/header.jsp" %>
<script>
    /* Aqui validaciones javascript, si las hubiere */
    function save(){
        var form = document.getElementById("rolForm");
        var options = form.seleccionadas.options;
        var len = options.length - 1;
        var i = 0;
        for (i = len; i >= 0; i--){
            options[i].selected = true;
        }
        form.submit();
    }
    
    function select(){
        var form = document.getElementById("rolForm");
        form.cmd.value = "seleccionarRol";
        form.nombre.value = "";
        form.descripcion.value="";
        form.submit();
    }
    
    function clean(){
        var form = document.getElementById("rolForm");
        form.codigo.value = "";
        form.nombre.value = "";
        form.descripcion.value="";
        form.roles.selectedIndex = "-1";
        form.cmd.value = "init";
    }
    
    function toRightList(){
        var form = document.getElementById("rolForm");
        var disponibles = form.disponibles;
        var seleccionadas = form.seleccionadas;
        var lenDis = disponibles.length - 1;
        var i = 0;
        for (i = lenDis; i >= 0; i--){
            if (disponibles.options[i].selected){
                disponibles.options[i].selected = false;
                seleccionadas.add(disponibles.options[i], 0);
            }
        }
    }
    
    function toLeftList(){
        var form = document.getElementById("rolForm");
        var disponibles = form.disponibles;
        var seleccionadas = form.seleccionadas;
        var lenSel = seleccionadas.length - 1;
        var i = 0;
        for (i = lenSel; i >= 0; i--){
            if (seleccionadas.options[i].selected){
                seleccionadas.options[i].selected = false;
                disponibles.add(seleccionadas.options[i], 0);
            }
        }
    }
    
    function cleanAndSubmit(){
        clean();
        var form = document.getElementById("rolForm");
        form.submit();
    }
</script>
                <div class="content">
                    <html:form action="/Rol" styleId="rolForm">
                        <html:hidden property="codigo" />
                        <logic:equal name="save" value="new">
                            <html:hidden property="cmd" value="agregarRol" />
                        </logic:equal>
                        <logic:notEqual name="save" value="new">
                            <html:hidden property="cmd" value="modificarRol" />
                        </logic:notEqual>
                        <table class="form">
                            <caption class="titleSeg">Mantenimiento de Roles</caption>
                            <tr class="campos">
                                <td rowspan="2" align="right" valign="top">Roles:&nbsp;&nbsp;</td>
                                <td rowspan="2" align="left" valign="top" width="225px">
                                    <html:select property="roles" onchange="select();" styleClass="tinput200" size="3">
                                        <html:options collection="rolesList" property="codigo"
                                                    labelProperty="nombre" labelName="nombre" />
                                    </html:select>
                                </td>
                                <td rowspan="2" width="50px">&nbsp;</td>
                                <td class="label">Nombre:*&nbsp;&nbsp;</td>
                                <td class="control"><html:text property="nombre" styleClass="tinput200" /></td>
                            </tr>
                            <tr class="campos">
                                <td class="label">Descripci&oacute;n:*&nbsp;&nbsp;</td>
                                <td class="control"><html:text property="descripcion" styleClass="tinput200" /></td>
                            </tr>
                            <tr>
                                <td valign="top">Disponibles:&nbsp;&nbsp;</td>
                                <td>
                                    <html:select property="disponibles" size="5" styleClass="tinput200" multiple="true">
                                        <html:options collection="availableList" property="codigo"
                                                    labelProperty="nombre" labelName="nombre" />
                                    </html:select>
                                </td>
                                <td valign="middle">
                                    <html:button property="derecha" value=">>" onclick="toRightList();" />
                                    <html:button property="izquierda" value="<<" onclick="toLeftList();" />
                                </td>
                                <td valign="top">Seleccionadas:&nbsp;&nbsp;</td>
                                <td>
                                    <html:select property="seleccionadas" size="5" styleClass="tinput200" multiple="true">
                                        <html:options collection="selectedList" property="codigo"
                                                    labelProperty="nombre" labelName="nombre" />
                                    </html:select>
                                </td>
                            </tr>
                            <logic:present name="msg">
                            <tr>
                                <td colspan="5" class="success">
                                    <html:img src="./images/ok.png" />&nbsp;
                                    <html:messages id="mensaje" name="msg">
                                        <bean:write name="mensaje" />
                                    </html:messages>
                                </td>
                            </tr>
                            </logic:present>
                            <logic:present name="errors">
                            <tr>
                                <td colspan="2" class="errors">
                                    <html:img src="./images/error.png" />&nbsp;<html:errors name="errors" />
                                </td>
                            </tr>
                            </logic:present>
                            <tr>
                                <td colspan="5">&nbsp;</td>
                            </tr>
                            <tr class="botones">
                                <td colspan="2">
                                    <div style="float: left">
                                        <html:button value="Guardar" property="guardar" styleClass="button" onclick="save();" />
                                        <html:button value="Limpiar" property="limpiar" onclick="cleanAndSubmit();" styleClass="button" />
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </html:form>
                </div>
<%@include file="/include/footer.jsp" %>
